<?php
/**
 * @description : config setting for TVB.COM. About CONST and some static vars.
 * @author      : stephen.mo <stephen.mo@achievo.com>
 * @date        : 2010/07/07
 */

class OAuthConfig {/*{{{*/

    //system cookies setting.
    const SET_COOKIE_EXPIRE_TIME        = 7;    //for oauth's cookie.
    const IS_ALLOW_COOKIE_VARS          = true;
    const USING_COOKIES                 = true;
  
    //set the base domain
    const BASE_DOMAIN                   = 'member.tvb.com';                    //need to change it ,when diffrent env.
    const DEFAULT_SUPPORT_LANG          = 'zh-hant-hk';
    const MOBILE_PAY_MEMBER_AC          = '#';
    const MOBILE_PAY_MYTV_AC            = '#';

    const MEMBER_FORGET_URL             = '/m/forget_password.php';
    const DEFAULT_AUTHORIZE_URL         = '/oauth/authorize.php';
    const DEFAULT_REQUEST_URL           = '/oauth/request_token.php';
    const DEFAULT_ACCESS_URL            = '/oauth/access_token.php';
    const DEFAULT_PCCW_LOGI_URL         = '#';

    //The third parties login setting 
    const DEFAULT_THIRD_PARTIES_URL     = '/m/thirdparties.php';
    const DEFAULT_AUTO_AUTHORIZE        = '/oauth/auto_authorize.php';
    const DEFAULT_REDIRECT_PAGE         = '/m/redirect.php';

    //normal ,must check or verify oauth_token and pukey(base function).
    const DEFAULT_HEADER_URL            = '/m/header.php'; 
    const DEFAULT_AJAX_URL              = '/m/m_ajax.php';
    const DEFAULT_CMODEL_URL            = '/m/plan_cmodel.php';
    const DEFAULT_CONFIRM_URL           = '/m/plan_confirm.php';
    const DEFAULT_CHOOSE_PLAN_URL       = '/m/plan_choose.php';
    const DEFAULT_INFORMATION_URL       = '/m/plan_information.php';
    const DEFAULT_REGISTER_URL          = '/m/register.php';
    const DEFAULT_PAYMENT_URL           = '/m/plan_payment.php';
    const DEFAULT_MESSAGE_URL           = '/m/plan_message.php';
    const DEFAULT_NOPAY_URL             = '/m/plan_free.php';
    const DEFAULT_QUICKLY_LOGIN         = '/m/plan_signin.php';
    const DEFAULT_REQUEST_PAGE          = '/m/plan_request.php';
    const DEFAULT_SHOW_MESSAGE_URL      = '/m/message.php';
    const DEFAULT_SUPPORT_PLAN_DETAILS  = '/m/plan_details.php';

    //special ,firt choose plan and payment ,then register member.
    const SPECIAL_HEADER_URL            = '/m/header.php';
    const SPECIAL_AJAX_URL              = '/m/m_ajax_spec.php';
    const SPECIAL_CMODEL_URL            = '/m/plan_cmodel_spec.php';
    const SPECIAL_CONFIRM_URL           = '/m/plan_confirm_spec.php';
    const SPECIAL_CHOOSE_PLAN_URL       = '/m/plan_choose_spec.php';
    const SPECIAL_INFORMATION_URL       = '/m/plan_information_spec.php';
    const SPECIAL_PAYMENT_URL           = '/m/plan_payment_spec.php';
    const SPECIAL_MESSAGE_URL           = '/m/plan_message.php';
    const SPECIAL_JOIN_REG_URL          = '/m/plan_joins_spec.php';
    const SPECIAL_NOPAY_URL             = '/m/plan_free_spec.php';
    
    //page value setting.
    const PAGE_PLAN_CMODEL              = 'plan_cmodel';
    const PAGE_PLAN_CHOOSE              = 'plan_choose';
    const PAGE_PLAN_CONFIRM             = 'plan_confirm';
    const PAGE_PLAN_INFORMATION         = 'plan_information';
    const PAGE_PLAN_JOINS               = 'plan_joins';
    const PAGE_PLAN_MESSAGE             = 'plan_message';
    const PAGE_PLAN_PAYMENT             = 'plan_payment';
    const PAGE_PLAN_FREE                = 'plan_free';
    const PAGE_TELCO_PAYMENT            = 'telcopayment';
    const PAGE_FORGET_PASSWORD          = 'forget_password';

    //special page value setting.
    const PAGE_PLAN_JCMODEL             = 'plan_cmodel_jf';
    const PAGE_PLAN_JCHOOSE             = 'plan_choose_jf';
    const PAGE_PLAN_JCONFIRM            = 'plan_confirm_jf';
    const PAGE_PLAN_JINFORMATION        = 'plan_information_jf';
    const PAGE_PLAN_JJOIN               = 'plan_joins_jf';
    const PAGE_PLAN_JMESSAGE            = 'plan_message_jf';
    const PAGE_PLAN_JPAYMENT            = 'plan_payment_jf';
    const PAGE_PLAN_JFREE               = 'plan_free_jf';
    
    //payment type.
    const PAGE_TYPE_PAYMENT             = 'm_payment';

    //error code list.
    const OAUTH_TOKEN_EXPIRED           = -1;
    const CALL_OAUTH_APIS_FAIL          = -2;
    const UPDATE_ACCESS_TOKEN_FAIL      = -3;
    const MISSING_NECESSARY_PARAM       = -4;
    const AUTHORIZED_REQUEST_TOKEN_FAIL = -5;
    const OTHER_OAUTH_ERROR             = -6;


    //get full web url with $_SERVER
    static public function OAuthGetRestUrl($server=array()) {/*{{{*/
        $http_url = NULL;
        $server = (!isset($server) || empty($server)) ? $_SERVER : $server;
        $scheme = (!isset($server['HTTPS']) || $server['HTTPS'] != "on") ? 'http' : 'https';
        $http_host = (strpos($server['HTTP_HOST'],':')===false) ? $server['HTTP_HOST'] : stristr($server['HTTP_HOST'],':',true);
        //$http_url = ($http_url) ? $http_url : $scheme .'://' . $http_host .':' .$server['SERVER_PORT'] .$server['REQUEST_URI'];
        $http_url = ($http_url) ? $http_url : $scheme .'://' . $http_host .$server['REQUEST_URI'];
        return $http_url;
    }/*}}}*/

    //get the server domain name and url.
    static public function OAuthDomainUrl($server=array()) {/*{{{*/
        $http_url  = NULL;
        $server    = (!isset($server) || empty($server)) ? $_SERVER : $server;
        $scheme    = (!isset($server['HTTPS']) || $server['HTTPS'] != "on") ? 'http' : 'https';
        //$http_host = (strpos($server['HTTP_HOST'],':')===false) ? $server['HTTP_HOST'] : stristr($server['HTTP_HOST'],':',true);
        //$http_url  = ($http_url) ? $http_url : $scheme .'://' . $http_host .':' .$server['SERVER_PORT'];
        $http_url = $scheme .'://' . $_SERVER['HTTP_HOST'] ;//.':' .$_SERVER['SERVER_PORT'];
        return $http_url;
    }/*}}}*/
    
    //get the back url from server data.
    static public function OAuthGetBackUrl($server=array()) {/*{{{*/
        $http_url = NULL;
        $tmp_data = array();
        $server   = (!isset($server) || empty($server)) ? $_SERVER : $server;
        $scheme   = (!isset($server['HTTPS']) || $server['HTTPS'] != 'on') ? 'http' : 'https';
        $http_host = (strpos($server['HTTP_HOST'],':')===false) ? $server['HTTP_HOST'] : stristr($server['HTTP_HOST'],':',true);
        $param_str = $server['QUERY_STRING'];
        parse_str($param_str,$params);
        if (isset($params['pukey'])) unset($params['pukey']);

        foreach($params as $key=>$val) {
            if (strpos($val,'http')!==false) $val = urlencode($val);
            $tmp_data[] = $key.'='.$val;
        }
        $params_string = '?'.implode('&',$tmp_data);
        $http_url  = ($http_url) ? $http_url : $scheme.'://'.$http_host.':'.$server['SERVER_PORT'].$server['PHP_SELF'].$params_string;
        return $http_url;
    }/*}}}*/
    
    //get the buy plan first page.
    static public function OAuthGetBuyPlanFirst($params=array()) {/*{{{*/
        $base_server_path = self::OAuthDomainUrl();
        $call_back   = (isset($params['call_back'])) ? $params['call_back'] : NULL;
        $reback_url  = (isset($params['reback_url'])) ? $params['reback_url'] : '#';
        $lang        = (isset($params['lang'])) ? $params['lang'] : self::DEFAULT_SUPPORT_LANG;
        $default_url = $base_server_path.self::DEFAULT_CMODEL_URL.'?call_back='.$call_back.'&reback_url='.$reback_url.'&lang='.$lang;
        return $default_url;
    }/*}}}*/

}/*}}}*/

?>
